﻿using System;

namespace TLang.Ast
{
    using Values;

    public class Assign : Node
    {
        public Node pattern;
        public Node value;


        public Assign(Node pattern, Node value, String file, int start, int end, int line, int col): base(file, start, end, line, col)
        {            ;
            this.pattern = pattern;
            this.value = value;
        }


        public override Value Interp(Scope s)
        {
            Value valueValue = value.Interp(s);
            Binder.CheckDup(pattern);
            Binder.Assign(pattern, valueValue, s);
            return Value.VOID;
        }

        public override Value Typecheck(Scope s)
        {
            Value valueValue = value.Typecheck(s);
            Binder.CheckDup(pattern);
            Binder.Assign(pattern, valueValue, s);
            return Value.VOID;
        }


        public override String ToString()
        {
            return "(" + Constants.ASSIGN_KEYWORD + " " + pattern + " " + value + ")";
        }
    }
}
